package service;

import java.util.List;


import common.DButil;
import vo.BookBean;


public class BookService {
	public  List<Object> get(int  bid){
		String sql="select b_num,b_price from book where b_id ="+bid+"" ;
		DButil db = DButil.getInstance();
		List<Object> list=db.excuteQuery(sql,BookBean.class );
		db.close();
		return list;
	}
	

	public  List<Object> get(){
		String sql="select distinct  b_type from book " ;
		DButil db = DButil.getInstance();
		List<Object> list=db.excuteQuery(sql,BookBean.class );
		db.close();
		return list;
	}
	public  void update(String bid){
		 String upsql="update book set b_num=b_num+1 where b_id='"+bid+"'";
			DButil db = DButil.getInstance();
			
			db.excuteUpdate(upsql);
		db.close();
		
	}
	public  void update(String bid,int bnum){
		 String upsql="update book set b_num=b_num+'"+bnum+"' where b_id='"+bid+"'";
			DButil db = DButil.getInstance();
			
			db.excuteUpdate(upsql);
		db.close();
		
	}
	public  void insert(String bname,String btype,String bnum,String bprice,String bauthor,String bpress,String bimage){
	String sql="insert into book values(null,'"+bname+"','"+btype+"','"+bnum+"','"+bprice+"','"+bauthor+"','"+bpress+"','"+bimage+"')";

		DButil db = DButil.getInstance();
		db.excuteUpdate(sql);
		db.close();	
	}
	//----------------------------------------------------------------------------
	public List<Object> getname(String a, int s, int b){
		 DButil tool = DButil.getInstance();
		   String sql="select b_name,b_num,b_image from book where b_name like'%"+a+"%' limit "+s+","+b+"";
		   DButil db = DButil.getInstance();
			List<Object> list=db.excuteQuery(sql,BookBean.class );
			
		   tool.close();
		return list;
	}
		public static List<String[]> getys(String a){
			DButil tool = DButil.getInstance();
			String sql1="select count(*) from book where b_name like'%"+a+"%'";
			DButil db = DButil.getInstance();
			List<String[]> list = db.excuteQuery(sql1);
			db.close();
			return list;
			
		}
		public  static List<Object> getall(int a,int b){
			   String sql="select b_name,b_num,b_image from book limit "+a+","+b+"";
			   DButil db = DButil.getInstance();
				List<Object> list=db.excuteQuery(sql,BookBean.class );
				db.close();

			return list;
		}
		public  static List<String[]> allcount(){
			   String sql="select count(*) from book";
			   DButil db = DButil.getInstance();
			   List<String[]> list = db.excuteQuery(sql);
			   db.close();
	           return list;
		}
	    public  static List<Object> gettype(int type,int a,int b){
	    	DButil tool = DButil.getInstance();
			   String sql="select b_name,b_num,b_image from book where b_type="+type+" limit "+a+","+b+"";
			   List<Object> list = tool.excuteQuery(sql,BookBean.class);
	           tool.close();
			return list;
		}
		public  static List<String[]> fen(int type){
			   String sql="select count(*) from book where b_type="+type+"";
			   DButil db = DButil.getInstance();
			   List<String[]> list = db.excuteQuery(sql);
			   db.close();
	        return list;
		}
		public  static List<Object> getxinxi(String b_name){
			DButil tool = DButil.getInstance();
			   String sql="select b_name,b_type,b_num,b_price,b_author,b_press,b_image from book where b_name='"+b_name+"'";
			   List<Object> list = tool.excuteQuery(sql,BookBean.class);
	          tool.close();
			return list;
		}
		
		public  static List<Object> getimage(String b_image){
			DButil tool = DButil.getInstance();
			   String sql="select b_name,b_type,b_num,b_price,b_author,b_press,b_image from book where b_image='"+b_image+"'";
			  
			   List<Object> list = tool.excuteQuery(sql,BookBean.class);         
			   tool.close();
			return list;
		}
		public static void excuteUpdate(String b_name,int b_num,int 
				b_type,String b_author,String b_press,double b_price, String b_image){
			DButil tool = DButil.getInstance();
			tool.excuteUpdate("insert book values(null,'"+b_name+"',"+b_type+","+b_num+","+b_price+",'"+b_author+"','"+b_press+"','"+b_image+"')");
		}
}
